package com.it.jdbc;

import com.mysql.cj.jdbc.Driver;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

/**
 * 修改数据
 */
public class JdbcUpdateDemo01 {
    public static void main(String[] args) {
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        try{
            //1.注册驱动
            DriverManager.registerDriver(new Driver());
            //2.获取连接
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql04","root","root");
            //3.编写sql
            //修改数据
            //String sql = "update account set name = ? , money = ? where id = ? ";
            //删除数据
            String sql = "delete from account where id = ?";
            preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setObject(1,3);
            //preparedStatement.setObject(2,4500);
            //preparedStatement.setObject(3,4);
            //4.执行sql
            boolean flag = preparedStatement.execute();
            System.out.println(flag);
            //5.打印结果
            preparedStatement.close();
            //6.关闭资源
            connection.close();
        }catch (Exception e){
            e.printStackTrace();
        }


    }
}
